package com.windystory.wslibrary.base.app;

import android.app.Application;
import android.content.Context;
import android.content.res.Resources;

import androidx.multidex.MultiDex;

/**
 * BaseApplication 必须继承
 */
public abstract class BaseApplication extends Application {
    /**
     * App字体是否跟随系统字体大小调节
     */
    public static boolean isChangeFontByUserChangeSystemFont = false;

    @Override
    public void onCreate() {
        super.onCreate();
        init();
    }


    //这是一个重新方法
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    protected abstract void init();

    @Override
    public Resources getResources() {
        //默认app字体跟随系统改变
        if (isChangeFontByUserChangeSystemFont)
            return super.getResources();
        else {
            //禁止app字体大小跟随系统字体大小调节
            Resources resources = super.getResources();
            if (resources != null && resources.getConfiguration().fontScale != 1.0f) {
                android.content.res.Configuration configuration = resources.getConfiguration();
                configuration.fontScale = 1.0f;
                resources.updateConfiguration(configuration, resources.getDisplayMetrics());
            }
            return resources;
        }
    }
}
